package rmmk.zadanie1;

public class Recurcively2 implements ISort {

	public Integer[] sort(Integer[] array) {
		Integer[] ar2 = array.clone(); 
		
		partition(ar2, 0, array.length-1);
		return ar2;
	}

	int partition(Integer[] arr, int left, int right)
	{
		int i = left, j = right;
		int tmp;
		int pivot = arr[(left + right) / 2];
		while (i <= j) {
			while (arr[i] < pivot)
				i++;
			while (arr[j] > pivot)
				j--;
			if (i <= j) {
				tmp = arr[i];
				arr[i] = arr[j];
				arr[j] = tmp;
				i++;
				j--;
			}
		};

		return i;
	}

}
